$(function () {
    $("#accordion").accordion({
        collapsible: true
    });
});
var date = new Date();
var currentYear = date.getFullYear();       // 当前年份
var currentMonth = date.getMonth() + 1;    // 当前月份
var currentDay = date.getDate();         // 今日日期 几号
if (currentMonth < 10) currentMonth = "0" + currentMonth;
if (currentDay < 10) currentDay = "0" + currentDay;
var nowTime = currentYear + "-" + currentMonth + "-" + currentDay;
$(".followRightHeader > button").click(function () {
    var index = $(this).index();
    $(this).addClass('Selection').siblings().removeClass('Selection');
    $(".followRightContents > div").eq(index).show().siblings().hide()
});

var count1 = 0;
submit.onclick = function () {//保存待计划
    var followStatus = $("#followStatus").val();
    var consumptionStatus = $("#consumptionStatus").val();
    var tcName = document.getElementById("tcName").value;   //tc
    var createName = document.getElementById("createName").value;  //创建人
    var revisit = document.getElementById("revisit").value;  //回访人员
    var remarks = document.getElementById("remarks").value;   //回访内容
    var revisitContent = document.getElementById("revisitContent").value;   //回访结果
    var reservationsId = document.getElementById("reservationsId").value;   //预约id
    var revisitTime = document.getElementById("revisitTime").value;   //回访时间
    var tcVisitId = document.getElementById("tcVisitId").value;   //ID
    if (revisit == null || revisit == "") {
        alert("请选择回访人员!");
        count1 = 0;
        return;
    }
    if (revisitTime.substring(0, 10) < nowTime && (followStatus == "" || followStatus == null || followStatus == "跟踪中")) {
        alert("下次跟进时间要不小于今天！");
        count1 = 0;
        return
    }
    if (followStatus == null || followStatus == "" || followStatus == "请选择") {
        alert("请选择跟踪状态!");
        count1 = 0;
        return;
    }
    if (consumptionStatus == null || consumptionStatus == "" || consumptionStatus == "请选择") {
        alert("请选择消费状态!");
        count1 = 0;
        return;
    }
    if ((remarks == null || remarks == "")) {
        alert("请填写回访计划!");
        count1 = 0;
        return;
    }
    count1++;
    if (count1 == 1) {
        $.ajax({
            url: Feng.ctxPath + "/tcRevisit/updateTcContent",
            type: "post",
            data: {
                tcName: tcName,
                followStatus: followStatus,
                consumptionStatus: consumptionStatus,
                revisitTime: revisitTime,
                createName: createName,
                remarks: remarks,
                revisitContent: revisitContent,
                reservationsId: reservationsId,
                tcVisitId: tcVisitId,
                revisit: revisit
            },
            success: function (data) {
                Feng.success('操作成功!');
                window.parent.TcFollowTableList.search();
                parent.layer.close(parent.layer.getFrameIndex(window.name))
            },
            error: function (data) {
                alert('没有权限，请联系管理员!');
            }
        });
    }
};

var count2 = 0;
submit2.onclick = function () {//回访完成
    var followStatus = $("#followStatus").val();
    var consumptionStatus = $("#consumptionStatus").val();
    var tcName = document.getElementById("tcName").value;   //tc
    var createName = document.getElementById("createName").value;  //创建人
    var revisit = document.getElementById("revisit").value;  //回访人员
    var remarks = document.getElementById("remarks").value;   //回访内容
    var revisitContent = document.getElementById("revisitContent").value;   //回访结果
    var reservationsId = document.getElementById("reservationsId").value;   //预约id
    var revisitTime = document.getElementById("revisitTime").value;   //回访时间
    var tcVisitId = document.getElementById("tcVisitId").value;   //ID
    if (revisit == null || revisit == "") {
        alert("请选择回访人员!");
        count2 = 0;
        return;
    }
    if (revisitTime.substring(0, 10) < nowTime && (followStatus == "" || followStatus == null || followStatus == "跟踪中")) {
        alert("下次跟进时间要不小于今天！");
        count2 = 0;
        return
    }
    if (followStatus == null || followStatus == "" || followStatus == "请选择") {
        alert("请选择跟踪状态!");
        count2 = 0;
        return;
    }
    if (consumptionStatus == null || consumptionStatus == "" || consumptionStatus == "请选择") {
        alert("请选择消费状态!");
        count2 = 0;
        return;
    }
    if ((revisitContent == null || revisitContent == "")) {
        alert("请填写回访结果!");
        count2 = 0;
        return;
    }
    count2++;
    if (count2 == 1) {
        $.ajax({
            url: Feng.ctxPath + "/tcRevisit/updateTcContent1",
            type: "post",
            data: {
                tcName: tcName,
                followStatus: followStatus,
                consumptionStatus: consumptionStatus,
                revisitTime: revisitTime,
                createName: createName,
                remarks: remarks,
                revisitContent: revisitContent,
                reservationsId: reservationsId,
                tcVisitId: tcVisitId,
                revisit: revisit
            },
            success: function (data) {
                Feng.success('操作成功!');
                window.parent.TcFollowTableList.search();
                $("#cancle").click();
            },
            error: function (data) {
                alert('没有权限，请联系管理员!');
            }
        });
    }
};

var countz = 0;
$("#submitZ").click(function () {
    var revisit = document.getElementById("revisit").value;   //回访人员
    var followStatus = $("#followStatus").val();
    var consumptionStatus = $("#consumptionStatus").val();
    var remarks = document.getElementById("remarks").value;   //回访内容
    if(revisit==null||revisit==""){
        alert("请选择回访人员!");
        countz = 0;
        return;
    }
    if(followStatus==null||followStatus==""){
        alert("请选择跟踪状态!");
        countz = 0;
        return;
    }
    if(consumptionStatus==null||consumptionStatus==""){
        alert("请选择消费状态!");
        countz = 0;
        return;
    }
    if(remarks==null||remarks==""){
        alert("请填写回访计划!");
        countz = 0;
        return;
    }
    var index = layer.open({
        type: 2,
        title: '再回访',
        area: ['60%', '50%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/tcRevisit/tc_followUp2'
    });
    this.layerIndex = index;
});

function addsf() {
    var index = layer.open({
        type: 2,
        title: '&nbsp',
        area: ['60%', '40%'],
        fix: true,
        maxmin: true,
        content: Feng.ctxPath + '/tcRevisit/to_addsf/'
    });
    this.layerIndex = index;
}

function addjg() {
    var index = layer.open({
        type: 2,
        title: '&nbsp',
        area: ['60%', '40%'],
        fix: true,
        maxmin: true,
        content: Feng.ctxPath + '/tcRevisit/to_addjg/'
    });
    this.layerIndex = index;
}

var count3 = 0;
submit3.onclick = function () {//取消回访
    var followStatus = $("#followStatus").val();
    var consumptionStatus = $("#consumptionStatus").val();
    var tcName = document.getElementById("tcName").value;   //tc
    var createName = document.getElementById("createName").value;  //创建人
    var revisit = document.getElementById("revisit").value;  //回访人员
    var remarks = document.getElementById("remarks").value;   //回访内容
    var revisitContent = document.getElementById("revisitContent").value;   //回访结果
    var reservationsId = document.getElementById("reservationsId").value;   //预约id
    var revisitTime = document.getElementById("revisitTime").value;   //回访时间
    var tcVisitId = document.getElementById("tcVisitId").value;   //ID
    if (revisit == null || revisit == "") {
        alert("请选择回访人员!");
        count3 = 0;
        return;
    }
    if (revisitTime.substring(0, 10) < nowTime && (followStatus == "" || followStatus == null || followStatus == "跟踪中")) {
        alert("下次跟进时间要不小于今天！");
        count3 = 0;
        return
    }
    if (followStatus == null || followStatus == "" || followStatus == "请选择") {
        alert("请选择跟踪状态!");
        count3 = 0;
        return;
    }
    if (consumptionStatus == null || consumptionStatus == "" || consumptionStatus == "请选择") {
        alert("请选择消费状态!");
        count3 = 0;
        return;
    }
    if ((remarks == null || remarks == "") && (revisitContent == null || revisitContent == "")) {
        alert("请填写回访计划或回访结果!");
        count3 = 0;
        return;
    }
    count3++;
    if (count3 == 1) {
        $.ajax({
            url: Feng.ctxPath + "/tcRevisit/updateTcContent2",
            type: "post",
            data: {
                tcName: tcName,
                followStatus: followStatus,
                consumptionStatus: consumptionStatus,
                revisitTime: revisitTime,
                createName: createName,
                remarks: remarks,
                revisitContent: revisitContent,
                reservationsId: reservationsId,
                tcVisitId: tcVisitId,
                revisit: revisit
            },
            success: function (data) {
                Feng.success('操作成功!');
                window.parent.TcFollowTableList.search();
                $("#cancle").click();
            },
            error: function (data) {
                alert('没有权限，请联系管理员!');
            }
        });
    }
}